import { ActionContext } from 'vuex'
import { IStore } from '@/store/types'
import { updateByPath } from '@/utils'

import {
  getAdsManageList,
  adsManageCopy,
  adsManageRemove,
  adgroupRecordInfo,
  adgroupRecordList,
  uploadAdgroup,
  adgroupCopy,
  adgroupAccountCodeList,
  adgroupBatchDelete,
  gdtAccountList,
  adgroupBatchList,
  accountExport,
  getCatalogsList,
  getCatalogsProductList,
  getTargetingTagsList,
  getTargetingList,
  gdtAdgroupsList,
  gdtAccountOwnerList,
  gdtAdgroupsBatchStatus,
  gdtCreativeBatchStatus,
  gdtCreativesList,
  adgroupsExport,
  creativesExport,
  gdtBatchAcquisition,
  gdtBatchPrice,
  gdtBatchDate,
  gdtBatchTime,
  gdtBatchDelete,
  gdtAdgroupsDetail,
  gdtMediaDetail, gdtCreativeBatchDelete
} from '@/api/intelligent'
import { ManageListParams, ManageReviewUpdateParams, ManageReviewCopyParams } from '@/api/model/intelligentModel'
import adv from '@/store/modules/adv'

export type IIntelligent = {
  data: IDataType
  siteSetList: any
  advertiser: any
  pageList: any
  batchGroup: string | number
}

export type IDataType = {
  accountName: string
  accountCode: null | string | number
  id: null | string | number
  base: any
  product: any
  creative: any
  position: any
  price: any
  adName: any
  target: any
  pageId: any
  batchGroup: string | number
}

const state = {
  data: {
    productInfo: adv.state.modal.market.productInfo
  }
}
const actions = {
  // 更新FORM值
  resetData({ commit }: any) {
    return new Promise<void>((resolve, reject) => {
      // commit('RESET_DATA')
      resolve()
    })
  },
  // 更新FORM值
  setData({ commit, state }: any, data: any) {
    return new Promise<void>((resolve, reject) => {
      commit('SET_DATA', data)
      resolve()
    })
  },
  async adgroupRecordInfo({}: ActionContext<IIntelligent, IStore>, params: any) {
    return await adgroupRecordInfo(params)
  },
  async adgroupRecordList({}: ActionContext<IIntelligent, IStore>, params: any) {
    return await adgroupRecordList(params)
  },
  async uploadAdgroup({}: ActionContext<IIntelligent, IStore>, params: any) {
    return await uploadAdgroup(params)
  },
  async adgroupCopy({}: ActionContext<IIntelligent, IStore>, params: any) {
    return await adgroupCopy(params)
  },
  async getAdsManageList({}: ActionContext<IIntelligent, IStore>, params: ManageListParams) {
    return await getAdsManageList(params)
  },
  async adsManageRemove({}: ActionContext<IIntelligent, IStore>, params: ManageReviewUpdateParams) {
    return await adsManageRemove(params)
  },
  async adsManageCopy({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await adsManageCopy(params)
  },
  async adgroupAccountCodeList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await adgroupAccountCodeList(params)
  },
  async adgroupBatchDelete({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await adgroupBatchDelete(params)
  },
  async gdtAccountList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtAccountList(params)
  },
  async adgroupBatchList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await adgroupBatchList(params)
  },
  async accountExport({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await accountExport(params)
  },
  async gdtAccountOwnerList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtAccountOwnerList(params)
  },
  async gdtAdgroupsList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtAdgroupsList(params)
  },
  async gdtAdgroupsDetail({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtAdgroupsDetail(params)
  },
  async adgroupsExport({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await adgroupsExport(params)
  },
  async creativesExport({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await creativesExport(params)
  },
  async gdtMediaDetail({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtMediaDetail(params)
  },
  async gdtAdgroupsBatchStatus({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtAdgroupsBatchStatus(params)
  },
  async gdtCreativeBatchStatus({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtCreativeBatchStatus(params)
  },
  async gdtBatchAcquisition({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtBatchAcquisition(params)
  },
  async gdtBatchPrice({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtBatchPrice(params)
  },
  async gdtBatchDate({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtBatchDate(params)
  },
  async gdtBatchTime({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtBatchTime(params)
  },
  async gdtBatchDelete({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtBatchDelete(params)
  },
  async gdtCreativeBatchDelete({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtCreativeBatchDelete(params)
  },
  async gdtCreativesList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await gdtCreativesList(params)
  },
  async getCatalogsList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await getCatalogsList(params)
  },
  async getCatalogsProductList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await getCatalogsProductList(params)
  },
  async getTargetingTagsList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await getTargetingTagsList(params)
  },
  async getTargetingList({}: ActionContext<IIntelligent, IStore>, params: ManageReviewCopyParams) {
    return await getTargetingList(params)
  }
}
const mutations = {
  // 更新form值
  SET_DATA: (state: { data: any }, req: { [x: string]: any }) => {
    for (const key in req) {
      updateByPath(state.data, key, req[key])
    }
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
